//
//  XiaoKaiSecondCollectionViewCell.m
//  Project_A
//
//  Created by 凯 on 15/7/21.
//  Copyright (c) 2015年 zhoukaidong. All rights reserved.
//

#import "XiaoKaiSecondCollectionViewCell.h"
#import "XiaoKaiUserCollectionView.h"
#import "BaseHeader.h"
#import "XiaoKaiItemsConfigCollectionViewCell.h"
@interface XiaoKaiSecondCollectionViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource>


@end


@implementation XiaoKaiSecondCollectionViewCell


-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self creatCollectionViewWith:CGRectMake(frame.origin.x, 0, frame.size.width, frame.size.height)];
    }
    return self;
}
-(void)creatCollectionViewWith:(CGRect)frame
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.sectionInset = UIEdgeInsetsMake(10, 5, 10, 5);
    layout.itemSize = CGSizeMake((SCREEN_WIDTH - 20) / 2, 200);
    layout.minimumLineSpacing = 5;
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) collectionViewLayout:layout];
//    _collectionView.bounces = NO;
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
    _collectionView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_collectionView];
    
    [self.collectionView registerClass:[XiaoKaiItemsConfigCollectionViewCell class] forCellWithReuseIdentifier:@"usercollectionviewcell"];

}




-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
   
    return self.dataSource.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    XiaoKaiItemsConfigCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"usercollectionviewcell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor redColor];
    UserModel *model = self.dataSource[indexPath.row];
    cell.Model = model;
    return cell;
}

-(void)setDataSource:(NSMutableArray *)dataSource{
    
    if ( _dataSource != dataSource) {
        [_dataSource release];
        _dataSource = [dataSource retain];
    }
    
    
    [_collectionView reloadData];
    
}


@end
